$(document).ready(function(){
  // 在这里写你的代码...
	var tb="";
	
	$.get("/findall", function(data){
        for(var i=0;i<data.length;i++){
        tb=tb+       " <tr>                                                                                             "+
        "     <td>"+data[i].stuid+"</td>                                                                              "+
        "     <td>"+data[i].name+"</td>                                                                           "+
        "     <td id='homeworkurl"+data[i].id+"'>"+data[i].homework+"</td>                                                                              "+
        "     <td>"+getdate(data[i].createTime)+"</td>                                                                              "+
        "     <td>"+data[i].score+"</td>                                                                                "+
        "     <td><button onclick='givescore("+data[i].id+")' class='btn btn-success' data-toggle='modal' data-target='#score'>评分</button>   "+
        "     <button class='btn btn-info' onclick='viewOnlineEvidence("+data[i].id+")' >下载</button>                                               "+
//        "     <button class='btn btn-warning' data-toggle='modal' data-target='#change'>修改</button>      "+
        "     <button  onclick='del("+data[i].id+")' id='delbtn" + data[i].id + "' type='button' class='btn btn-danger'>删除</button>                                                "+
        "     </td>                                                                                        "+
        "                                                                                                  "+
        " </tr>                                                                                            "	    	
        }
        $("#tb").html(tb);
});
	

	function getdate(time) {
        var now = new Date(time),
            y = now.getFullYear(),
            m = ("0" + (now.getMonth() + 1)).slice(-2),
            d = ("0" + now.getDate()).slice(-2);
        return y + "-" + m + "-" + d ;
    };
	
del=function (id) {
	    $.post("/del", { id:id } );
	    window.location.href = '/index.html';
	};
	
givescore=function(id){
	$("#studentid").val(id);
	var studentid=$("#studentid").val();
	console.log("****studentid="+studentid)
	};
	
download=function exportFile(){        
        var form=$("<form>");
        form.attr("style","display:none");
        form.attr("target","");
        form.attr("method","post");//提交方式为post
        form.attr("action","/downloadFile");//定义action
        
        $("body").append(form);
        form.submit();        
   };

viewOnlineEvidence=function(id){
	var homeworkurl=$("#homeworkurl"+id).html()
	console.log(homeworkurl);
	console.log(homeworkurl.split("\/"));
	console.log(homeworkurl.split("\/")[homeworkurl.split("\/").length-1]);
	var homeworkname=homeworkurl.split("\/")[homeworkurl.split("\/").length-1];
	 window.location.href = '/downloadOnlineLearnMaterials?filename='+homeworkname;
}
	

$("#scoresubbtn").click( function () {
	var score=$("#sc").val();
	var id=$("#studentid").val();
	$.post("/giveScore", { score: score, id: id },
	          function(data){
		 window.location.href = '/index.html';
	          });
	});
});